<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function () {
            //设置全选
            var itm = document.getElementsByName("items");
            var all = document.getElementById("all");
            var allName = document.getElementsByName("allName");
            all.onclick = function () {

                for (var i = 0; i < itm.length; i++) {
                    itm[i].checked = true;
                }
            }
            //设置全不选
            var all = document.getElementById("close");
            all.onclick = function () {
                for (var i = 0; i < itm.length; i++) {
                    itm[i].checked = false;
                }
            }
            //反选
            var all = document.getElementById("rev");
            all.onclick = function () {
                for (var i = 0; i < itm.length; i++) {
                    itm[i].checked = !itm[i].checked;
                }
            }
            //提交
            var all = document.getElementById("send");
            all.onclick = function () {
                for (var i = 0; i < itm.length; i++) {
                    if (itm[i].checked == true) {
                        alert(itm[i].value);
                    }
                }
            }
        };
    </script>
</head>

<body>
    <form>

        你的爱好运动是？<input type="checkbox" name="allName" value="全部">全选/全不选<br />
        <input type="checkbox" name="items" value="足球">足球
        <input type="checkbox" name="items" value="篮球">篮球
        <input type="checkbox" name="items" value="乒乓球">乒乓球
        <input type="checkbox" name="items" value="羽毛球">羽毛球
        <br />
        <input type="button" id="all" value="全选">
        <input type="button" id="close" value="全不选">
        <input type="button" id="rev" value="反选">
        <input type="button" id="send" value="提交">

    </form>
</body>

</html>